package demo2;

class Person implements Comparable<Person>{
    @Override
    public int compareTo(Person o) {
        return 0;
    }
}
class Alg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg2 {
    public<E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg3 {
    public static <E extends Comparable<E>>  E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}

public class Test {
    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,45,5,6,8};
        int ret = Alg3.findMax(array);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,2,3,4,45,5,6,8};
        int ret = alg2.findMax(array);
        //int ret = alg2.<Integer>findMax(array);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
        Integer[] array = {1,2,3,4,45,5,6,8};
        Alg<Integer> alg = new Alg<>();
        int a = alg.findMax(array);
        System.out.println(a);

        Alg<Person> alg23 = new Alg<Person>();

    }
}
